<%@ page language="java" contentType="text/html; charset=UTF-8"
         pageEncoding="UTF-8" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
    <jsp:include page="../../../../../head.jsp"/>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>权限列表</title>
</head>
<script type="text/javascript">
    var roleId = "${rid}";
    var moduleId = "${mid}";
    var dataUrl = "role-perdata?rid=" + roleId + "&mid="
                  + moduleId;
    var pTree;
    var setting = {
        async: {
            enable: true,
            url: dataUrl,
            dataFilter: function (treeId, parentNode, childNodes) {
                if (!childNodes)
                    return null;
                roleId = childNodes.role.id;
                return childNodes.role.permissions;
            }
        },
        check: {
            enable: true
        },
        data: {
            simpleData: {
                pIdKey: "parent.id"
            }
        },
        callback: {}
    };

    function save() {
        if (roleId) {
            var changeNodes = pTree.getChangeCheckedNodes();
            var checkedNodes = pTree.getCheckedNodes();
            if (changeNodes != null && changeNodes.length != 0) {
                submitTree(checkedNodes, "role-saveRoleManagePer", {
                    "managePermissions{n}.id": "id",
                    "managePermissions{n}.checked": "checked"
                }, {
                               "id": roleId
                           }, "n", function (data, textStatus, jqXHR) {
                    jw.alert(data.msg, {
                        onOk: function () {
                            if (data.result) {
                                tree_refresh(zTree);
                            }
                        }
                    });
                });
            }
        }
    }

    var checkedAll = false;
    function checkAll(obj) {
        if (checkedAll) {
            obj.value = "全选";
        } else {
            obj.value = "全取消";
        }
        checkedAll = !checkedAll;
        pTree.checkAllNodes(checkedAll);
    }

    $(document).ready(function () {
        $.fn.zTree.init($("#perTree"), setting);
        pTree = $.fn.zTree.getZTreeObj("perTree");
        $("input:button").button();
    });
</script>
<body>
<div>
    <ul id="perTree" class="ztree"></ul>
    <div align="center">
        <input class="btn" type="button" onclick="checkAll(this)" value="全选"/>
        <input class="btn" type="button" onclick="save()" value="保存"/> <input
            class="btn" type="button" onclick="tree_refresh(pTree)" value="重置"/>
    </div>
</div>
</body>
</html>
